# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: damir <damir@archlinux.org>

pkgname=fluidsynth
pkgver=2.3.4
pkgrel=1
pkgdesc="A real-time software synthesizer based on the SoundFont 2 specifications"
arch=(loong64 x86_64)
url="https://www.fluidsynth.org/"
license=(LGPL-2.1-or-later)
groups=(pro-audio)
depends=(
  gcc-libs
  glibc
  sdl2
)
makedepends=(
  alsa-lib
  cmake
  dbus
  doxygen
  glib2
  jack
  ladspa
  libinstpatch
  libpipewire
  libpulse
  libsndfile
  portaudio
  readline
  systemd-libs
)
provides=(
  libfluidsynth.so
  soundfont-synthesizer
)
backup=(etc/conf.d/$pkgname)
source=($pkgname-$pkgver.tar.gz::https://github.com/$pkgname/$pkgname/archive/v$pkgver.tar.gz)
sha512sums=('79891116d78b9be1c38bce9e5759b9bb732c3d8ee31c6e57d1a3e2b5548879b91d19582e73ee7fb0fd243beba3bf1bbc341a26aab0b6440eef36fc55dce3e8b0')
b2sums=('5146c1f0243ac1fcc3d4f29ea65bb03b326c59bf9de1f53def447f4a924c7fdde31f8b33300051d2e7765087fb8bbdba3643b03c537e3366b02ca42b3b9d4311')

build() {
  local cmake_options=(
    -B build
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
    -D FLUID_DAEMON_ENV_FILE=/etc/conf.d/fluidsynth
    -D LIB_SUFFIX=""
    -D enable-ladspa=ON
    -D enable-portaudio=ON
    -S $pkgname-$pkgver
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
}

check() {
  make check -k -C build
}

package() {
  depends+=(
    alsa-lib libasound.so
    dbus libdbus-1.so
    glib2 libglib-2.0.so libgmodule-2.0.so libgobject-2.0.so
    jack libjack.so
    libinstpatch libinstpatch-1.0.so
    libpipewire libpipewire-0.3.so
    libpulse libpulse-simple.so
    libsndfile libsndfile.so
    portaudio libportaudio.so
    readline libreadline.so
    systemd-libs libsystemd.so
  )

  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 build/$pkgname.service -t "$pkgdir/usr/lib/systemd/user/"
  install -vDm 644 build/$pkgname.conf "$pkgdir/etc/conf.d/$pkgname"
  install -vDm 644 $pkgname-$pkgver/{AUTHORS,ChangeLog,{CONTRIBUTING,README}.md,THANKS,TODO} -t "$pkgdir/usr/share/doc/$pkgname/"
}
